package game.games.rpg.magic;

import game.games.rpg.AttributedObject;

public abstract class AbstractBuff extends AttributedObject
{
    private int startTick;
    private int duration;
    private int tickFactor;
    
    public AbstractBuff(int startTick, int duration, int tickFactor)
    {
        this.startTick = startTick;
        this.duration = duration;
        this.tickFactor = tickFactor;
    }
    
    public void setStartTick(int startTick)
    {
        this.startTick = startTick;
    }
    
    public void setDuration(int duration)
    {
        this.duration = duration;
    }
    
    public boolean isActive(int currentTick)
    {
        return currentTick < startTick + duration;
    }
    
    protected boolean tick(int currentTick)
    {
        return (tickFactor == 0 || ((currentTick - startTick) % tickFactor == 0));
    }
    
    public void next(int currentTick)
    {
        if (isActive(currentTick) && tick(currentTick))
        {
            doIt();
        }
    }
    
    protected abstract void doIt();
}
